﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;
using System.Collections;

namespace EnvironmentManagerSystem
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                if (Session["UserName"].ToString().Length > 4)
                {
                    use.Text = Session["UserName"].ToString().Substring(0, 4);
                    use.ToolTip = Session["UserName"].ToString();
                }
                else
                {
                    use.Text = Session["UserName"].ToString();
                    use.ToolTip = Session["UserName"].ToString();
                }
                time.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                la.Text = Session["roleid"].ToString();
                BindCount();
                labID.Text = Session["roleid"].ToString();               
                //Panel1.Visible = false;
            }
        }


        #region BindCount
        private void BindCount()
        {
            foreach (string RoleID in Session["roleid"].ToString().Split(','))
            {
                #region (RoleID == "中心领导")
                if (RoleID == "中心领导")
                {
                    //1项目受理(项目受理确认人为空)
                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu is NULL and NoticeState!=2 and projectreportstate=1") + "条";
                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
                    {
                        labXiangMuShouLiDaiQueRen.Visible = false;
                    }
                    else
                    {
                        labXiangMuShouLiDaiQueRen.Visible = true;
                    }
                    //2部门分配(部门分配确认人为空and项目必须以受理)
                    this.lblBuMenFengPei.Text = "待分配项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu=1 and fenpeiquerenren is NULL and NoticeState!=2") + "条";
                    if (lblBuMenFengPei.Text == "待分配项目：0条")
                    {
                        lblBuMenFengPei.Visible = false;
                    }
                    else
                    {
                        lblBuMenFengPei.Visible = true;
                    }
                    //3项目负责(项目负责确认人为空and项目必须以受理and项目负责状态)
                    this.lblXiangMuFeZe.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu=1 and NoticeState!=2 AND (fuzetuihuiqueren is NULL OR (fuzetuihuiqueren = 1 
                                AND NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=xiangmufuzequerenren))))") + "条";
                    if (lblXiangMuFeZe.Text == "待确认项目：0条")
                    {
                        lblXiangMuFeZe.Visible = false;
                    }
                    else
                    {
                        lblXiangMuFeZe.Visible = true;
                    }
                    //4现场踏查(含踏查=1and项目必须以受理and踏查退回删除=1and登录人不是中心领导)
                    this.labXianChangTaCha.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE hantacha=1 and NoticeState!=2 and shoulituihuishanchu=1 and (tachaquerentuihui is NULL or (tachaquerentuihui=1 
                                                               and NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=tachaquerenren))))") + "条";
                    if (labXianChangTaCha.Text == "待确认项目：0条")
                    {
                        labXianChangTaCha.Visible = false;
                    }
                    else
                    {
                        labXianChangTaCha.Visible = true;
                    }
                    //5专家会议(含会议=1and受理退回删除=1and专家会议确认人为空and会议确认=1and登录人是不是中心领导)
                    this.labZhuanJiaHuiYi.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE hanhuiyi=1 and NoticeState!=2 and shoulituihuishanchu=1 and (huiyiqueren is NULL or (huiyiqueren=1 
                                                               and NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=zhuanjiahuiyiquerenren))))") + "条";
                    if (labZhuanJiaHuiYi.Text == "待确认项目：0条")
                    {
                        labZhuanJiaHuiYi.Visible = false;
                    }
                    else
                    {
                        labZhuanJiaHuiYi.Visible = true;
                    }
                    //6评估意见(受理退回删除=1and复审会议确认=1andand登录人是不是中心领导)
                    this.labPingGuYiJian.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu=1 and NoticeState!=2 and (queren is NULL or (queren=1 
                                                               and NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=pingguyijianchuliren))))") + "条";
                    if (labPingGuYiJian.Text == "待确认项目：0条")
                    {
                        labPingGuYiJian.Visible = false;
                    }
                    else
                    {
                        labPingGuYiJian.Visible = true;
                    }
                    //7项目考察(受理退回删除=1and项目考察确认人为空and登录人是不是中心领导)
                    this.labXiangMuKaoCha.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu=1 and NoticeState!=2 and (xiangmukaopingchuliren is NULL or (xiangmukaopingchuliren IS NOT NULL 
                                                               and NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=xiangmukaopingchuliren))))") + "条";
                    if (labXiangMuKaoCha.Text == "待确认项目：0条")
                    {
                        labXiangMuKaoCha.Visible = false;
                    }
                    else
                    {
                        labXiangMuKaoCha.Visible = true;
                    }
                    //8汇总上报(受理退回删除=1and汇总上报状态=1and登录人是不是中心领导)
                    this.labHuiZongShangBao.Text = "待确认项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu=1 and NoticeState!=2 and (reportstate is NULL or (reportstate=1 
                                                               and NOT FIND_IN_SET('中心领导',(SELECT RoleId FROM tbs001_user WHERE UserName=reportpeople))))") + "条";
                    if (labHuiZongShangBao.Text == "待确认项目：0条")
                    {
                        labHuiZongShangBao.Visible = false;
                    }
                    else
                    {
                        labHuiZongShangBao.Visible = true;
                    }
                }
                #endregion

                #region (RoleID == "受理人")
                if (RoleID == "受理人")
                {
                    //1项目受理(项目受理确认人为空)
                    this.labXiangMuShouLiDaiQueRen.Text = "待受理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE shoulituihuishanchu is NULL and NoticeState!=2 and projectreportstate=1") + "条";
                    if (labXiangMuShouLiDaiQueRen.Text == "待受理项目：0条")
                    {
                        labXiangMuShouLiDaiQueRen.Visible = false;
                    }
                    else
                    {
                        labXiangMuShouLiDaiQueRen.Visible = true;
                    }
                }
                #endregion

                #region (RoleID == "部门负责人")
                if (RoleID == "部门负责人")
                {
                    //3项目负责(分配确认人不为空and项目负责状态不为空andand分配的执行部门是他所在的)
                    this.lblXiangMuFeZe.Text = "待处理项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE fenpeiquerenren is not NULL and NoticeState!=2 AND fuzetuihuiqueren is NULL
                                                               AND FIND_IN_SET(" + int.Parse(Session["ID"].ToString()) + ",(SELECT ed_User FROM tbs001_executivedepartment WHERE ed_Name=fenpeizhixingbumen))") + "条";
                    if (lblXiangMuFeZe.Text == "待处理项目：0条")
                    {
                        lblXiangMuFeZe.Visible = false;
                    }
                    else
                    {
                        lblXiangMuFeZe.Visible = true;
                    }
                }
                #endregion

                #region (RoleID == "项目负责人" || RoleID == "部门负责人")
                if (RoleID == "项目负责人" || RoleID == "部门负责人")
                {
                    //4现场踏查(评审项目负责人为自己and踏查确认退回为空and含踏查)
                    this.labXianChangTaCha.Text = "待处理项目：" + BLL.HuanJing.GetCount(@"SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE pingshenxiangmufuzeren='" + Session["UserName"].ToString() + "' and tachaquerentuihui is NULL and NoticeState!=2 and hantacha=1") + "条";
                    if (labXianChangTaCha.Text == "待处理项目：0条")
                    {
                        labXianChangTaCha.Visible = false;
                    }
                    else
                    {
                        labXianChangTaCha.Visible = true;
                    }
                    //5专家会议(评审项目负责人为自己and会议确认为空)
                    this.labZhuanJiaHuiYi.Text = "待处理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE  hanhuiyi=1 and pingshenxiangmufuzeren='" + Session["UserName"].ToString() + "' and huiyiqueren is NULL and NoticeState!=2") + "条";
                    if (labZhuanJiaHuiYi.Text == "待处理项目：0条")
                    {
                        labZhuanJiaHuiYi.Visible = false;
                    }
                    else
                    {
                        labZhuanJiaHuiYi.Visible = true;
                    }
                    //6评估意见(评审项目负责人为自己and复审会议为空)
                    this.labPingGuYiJian.Text = "待处理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE pingshenxiangmufuzeren='" + Session["UserName"].ToString() + "' and queren is NULL and NoticeState!=2") + "条";
                    if (labPingGuYiJian.Text == "待处理项目：0条")
                    {
                        labPingGuYiJian.Visible = false;
                    }
                    else
                    {
                        labPingGuYiJian.Visible = true;
                    }
                    //7项目考察(评审项目负责人为自己and项目考评处理人为空)
                    this.labXiangMuKaoCha.Text = "待处理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE pingshenxiangmufuzeren='" + Session["UserName"].ToString() + "' and xiangmukaopingchuliren is NULL and NoticeState!=2") + "条";
                    if (labXiangMuKaoCha.Text == "待处理项目：0条")
                    {
                        labXiangMuKaoCha.Visible = false;
                    }
                    else
                    {
                        labXiangMuKaoCha.Visible = true;
                    }
                    //8汇总上报(评审项目负责人为自己and汇总上报状态等于空)
                    this.labHuiZongShangBao.Text = "待处理项目：" + BLL.HuanJing.GetCount("SELECT COUNT(*) FROM tbs001_developprojectbasicinfo WHERE pingshenxiangmufuzeren='" + Session["UserName"].ToString() + "' and reportstate is NULL and NoticeState!=2") + "条";
                    if (labHuiZongShangBao.Text == "待处理项目：0条")
                    {
                        labHuiZongShangBao.Visible = false;
                    }
                    else
                    {
                        labHuiZongShangBao.Visible = true;
                    }
                }
                #endregion
            }
        }
        #endregion
    }
}
